var prefix = ctx + "app/warningsub"
$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		doMatch();
	}
});

function doMatch(){
	var form = document.getElementById("signupForm");
	var formData = new FormData(form);
	var fileType = formData .get("file").type;
	if (fileType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
		&& fileType != "application/vnd.ms-excel") {
		layer.msg("预警文件只支持.xls和.xlsx");
		return;
	}
	
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix + "/doMatch",
		data : formData, 
		async : false,
		processData: false,
	    contentType: false,
	    error : function(request) {
			parent.layer.alert("网络超时");
		},
		success : function(data) {
			if (data.code == 0) {
				layer.msg(data.msg);
				$("#file").val("");
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				layer.alert(data.msg)
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			
		},
		messages : {
			
		},
	})
}

function initTemplateDownLoad() {
	var inspectType = $('#inspectType').val();
	if(inspectType == 1){
		$('#downTemplate').html('<a href="/upload/inspectTemplate/企业模板.xlsx">企业模板</a>');
	}else if(inspectType == 2){
		$('#downTemplate').html('<a href="/upload/inspectTemplate/自然人模板.xlsx">自然人模板</a>');
	}
}



